package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysBanner;
import com.ruoyi.system.service.ISysBannerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动内容Controller
 * 
 * @author wolong
 * @date 2023-03-13
 */
@Api("页面banner信息和活动信息管理")
@RestController
@RequestMapping("/system/banner")
public class SysBannerController extends BaseController
{
    @Autowired
    private ISysBannerService sysBannerService;

    /**
     * 查询活动内容列表
     */
    @ApiOperation("获取banner列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bannerId", value = "活动主键", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "name", value = "活动名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "imgUrl", value = "活动图片连接", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "bannerType", value = "活动类型枚举(0首页顶部 1早检查)", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "contentType", value = "内容枚举(0图片 1视频 2图文 3文章连接)", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "description", value = "活动描述", dataType = "String", dataTypeClass = String.class),
    })
//    @PreAuthorize("@ss.hasPermi('system:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBanner sysBanner)
    {
        startPage();
        List<SysBanner> list = sysBannerService.selectSysBannerList(sysBanner);
        return getDataTable(list);
    }

    /**
     * 导出活动内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:banner:export')")
    @Log(title = "活动内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBanner sysBanner)
    {
        List<SysBanner> list = sysBannerService.selectSysBannerList(sysBanner);
        ExcelUtil<SysBanner> util = new ExcelUtil<SysBanner>(SysBanner.class);
        util.exportExcel(response, list, "活动内容数据");
    }

    /**
     * 获取活动内容详细信息
     */
    @ApiOperation("获取banner详细信息")
//    @PreAuthorize("@ss.hasPermi('system:banner:query')")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return success(sysBannerService.selectSysBannerByBannerId(bannerId));
    }

    /**
     * 新增活动内容
     */
    @PreAuthorize("@ss.hasPermi('system:banner:add')")
    @Log(title = "活动内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBanner sysBanner)
    {
        return toAjax(sysBannerService.insertSysBanner(sysBanner));
    }

    /**
     * 修改活动内容
     */
    @PreAuthorize("@ss.hasPermi('system:banner:edit')")
    @Log(title = "活动内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBanner sysBanner)
    {
        return toAjax(sysBannerService.updateSysBanner(sysBanner));
    }

    /**
     * 删除活动内容
     */
    @PreAuthorize("@ss.hasPermi('system:banner:remove')")
    @Log(title = "活动内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(sysBannerService.deleteSysBannerByBannerIds(bannerIds));
    }
}
